<template>
  <a-modal
    title="发货"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="
      () => {
        this.visible = false
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="试用是否成功">
          <a-radio-group v-model="entity.SampleStatus" :default-value="1" button-style="solid">
            <a-radio-button :value="1"> 是 </a-radio-button>
            <a-radio-button :value="2"> 否 </a-radio-button>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item label="说明" prop="SampleTrialRemark">
          <a-textarea v-model="entity.SampleTrialRemark" autocomplete="off" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      loading: false,
      imageUrl: '',
      headers: '',
      id: '',
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    openForm(id) {
      this.init()
      this.visible = true
      this.id = id
    },

    handleSubmit() {
      let searchArr = []
      if (this.entity.SampleTrialRemark) {
        searchArr = [
          {
            Condition: 'SampleTrialRemark',
            Keyword: this.entity.SampleTrialRemark
          },
          {
            Condition: 'SampleStatus',
            Keyword: this.entity.SampleStatus
          }
        ]
      } else {
        searchArr = [
          {
            Condition: 'SampleStatus',
            Keyword: this.entity.SampleStatus
          }
        ]
      }
      this.$http
        .post('/SampleManagement/SPL_SampleApplyMain/UpdateDataByCondition', {
          Conditions: searchArr,

          ids: [this.id]
        })
        .then(resJson => {
          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
    },
    init() {
      this.visible = true
      this.entity = {}
      this.$set(this.entity, 'SampleStatus', 1)
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    }
  }
}
</script>
